package com.moxiao.yfjh.module.blind.dal.mysql.memberSayHello;

import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.MemberSayhelloPageReqVO;
import com.moxiao.yfjh.module.blind.controller.app.controller.exchage.vo.AppMemberSayhelloReqVO;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberLike.MemberLikeDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberSayHello.MemberSayhelloDO;
import java.util.*;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import com.moxiao.yfjh.module.blind.controller.admin.memberSayHello.vo.*;

/**
 * 相亲会员打招呼 Mapper
 *
 * @author mx
 */
@Mapper
public interface MemberSayhelloMapper extends BaseMapperX<MemberSayhelloDO> {

    default PageResult<MemberSayhelloDO> selectPage(MemberSayhelloPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberSayhelloDO>()
                .eqIfPresent(MemberSayhelloDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberSayhelloDO::getIssue, reqVO.getIssue())
                .eqIfPresent(MemberSayhelloDO::getReceive, reqVO.getReceive())
                .eqIfPresent(MemberSayhelloDO::getContent, reqVO.getContent())
                .eqIfPresent(MemberSayhelloDO::getSayHello, reqVO.getSayHello())
                .eqIfPresent(MemberSayhelloDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberSayhelloDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberSayhelloDO::getId));
    }

    default List<MemberSayhelloDO> selectList(MemberSayhelloExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MemberSayhelloDO>()
                .eqIfPresent(MemberSayhelloDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberSayhelloDO::getIssue, reqVO.getIssue())
                .eqIfPresent(MemberSayhelloDO::getReceive, reqVO.getReceive())
                .eqIfPresent(MemberSayhelloDO::getContent, reqVO.getContent())
                .eqIfPresent(MemberSayhelloDO::getSayHello, reqVO.getSayHello())
                .eqIfPresent(MemberSayhelloDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberSayhelloDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberSayhelloDO::getId));
    }

    default List<MemberSayhelloDO> selectSayHelloList(AppMemberSayhelloReqVO reqVO) {
        LambdaQueryWrapperX<MemberSayhelloDO> memberSayhelloDOLambdaQueryWrapperX = new LambdaQueryWrapperX<MemberSayhelloDO>()
                .eqIfPresent(MemberSayhelloDO::getUserId, reqVO.getUserId())
                .eqIfPresent(MemberSayhelloDO::getContent, reqVO.getContent())
                .eqIfPresent(MemberSayhelloDO::getSayHello, reqVO.getSayHello())
                .eqIfPresent(MemberSayhelloDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(MemberSayhelloDO::getCreateTime, reqVO.getCreateTime());
            memberSayhelloDOLambdaQueryWrapperX.notLike(MemberSayhelloDO::getAuditStatus,(byte) 2);

            if(StringUtils.isNotEmpty(reqVO.getIssue())){
                memberSayhelloDOLambdaQueryWrapperX.and(wrapper->wrapper.eq(MemberSayhelloDO::getIssue, reqVO.getIssue()))
                        .or(wrapper->wrapper.eq(MemberSayhelloDO::getReceive, reqVO.getIssue()).eq(MemberSayhelloDO::getSayHello, (byte) 1));
            }
            if(StringUtils.isNotEmpty(reqVO.getReceive())){
                memberSayhelloDOLambdaQueryWrapperX.and(wrapper->wrapper.eq(MemberSayhelloDO::getReceive, reqVO.getReceive()))
                        .or(wrapper->wrapper.eq(MemberSayhelloDO::getIssue, reqVO.getReceive()).eq(MemberSayhelloDO::getSayHello, (byte) 1));
            }
            if (Objects.equals(reqVO.getHaveMember(),1)){
                memberSayhelloDOLambdaQueryWrapperX.orderByDesc(MemberSayhelloDO::getId);
            }else {
                memberSayhelloDOLambdaQueryWrapperX.orderByAsc(MemberSayhelloDO::getId);
            }
        return selectList(memberSayhelloDOLambdaQueryWrapperX);
    }
}
